//
//  CTVClip.m
//  Channltv
//
//  Created by Bruno Keymolen on 7/5/07.
//  Copyright 2007 channl.tv. All rights reserved.
//

#import "CTVClip.h"
#import "CTVCache.h"

@implementation CTVClip


 -(void) init{
 
	m_title		= nil;
	m_info		= nil;
	m_url		= nil;
	m_thumbUrl	= nil;
	m_clipID	= nil;
	
	[super init];
 }


-(void) dealloc{ 
//	NSLog(@"CTVClip - dealloc");

	if(m_pChannel)
		[m_pChannel autorelease];
		//[m_pChannel release];

	if(m_thumbTexture)
		[m_thumbTexture release];
		
	if(m_title)
		[m_title release];	
	
	if(m_info)
		[m_info release];	

	if(m_url)
		[m_url release];

	if(m_thumbUrl)
		[m_thumbUrl release];

	if(m_clipID)
		[m_clipID release];

	if(m_menuItemLayer)
		[m_menuItemLayer release];
	
	[super dealloc]; //do not forget to transmit to the superclass 
} 


-(void)setTitle:(NSString*) title{
	[title retain];
	[m_title release];
	m_title = title;
}

-(NSString*)getTitle{
	return m_title;
}


-(void)setUrl:(NSString*) url{
	[url retain];
	[m_url release];
	m_url = url;
}

-(NSString*)getUrl{
	return m_url;
}


-(void)setInfo:(NSString*) info{
	[info retain];
	[m_info release];
	m_info = info;
}

-(NSString*)getInfo{
	return m_info;
}


-(void)setThumbUrl:(NSString*) thumbUrl{
	[thumbUrl retain];
	[m_thumbUrl release];
	m_thumbUrl = thumbUrl;
}


-(NSString*)getThumbUrl{
	return m_thumbUrl;
}
 
-(void)setDuration:(long)duration{
	m_duration = duration;
}

-(long)getDuration{
	return m_duration;
}


-(BOOL)autoSyncMedia{
	return m_autoSyncMedia;
}

-(BOOL)privateMedia{
	return m_privateMedia;
}

-(BOOL)streamMedia{
	return m_streamMedia;
}

-(void)setAutoSyncMedia:(BOOL)val{
	m_autoSyncMedia = val;
}

-(void)setPrivateMedia:(BOOL)val{
	m_privateMedia = val;
}

-(void)setStreamMedia:(BOOL)val{
	m_streamMedia = val;
}

-(BRBitmapTexture*)thumbTexture{
	return m_thumbTexture;
}

-(void)setThumbTexture:(BRBitmapTexture*)texture{
	if(m_thumbTexture)
		[m_thumbTexture release];
		
	m_thumbTexture = texture;
	[m_thumbTexture retain];	
}

-(void)loadBitmapTextureForScene:(BRRenderScene*)scene{
	NSString* cachePath = [CTVCache getResourceCachePathForURL:m_thumbUrl];
	BRBitmapTexture* texture = [CTVCache createBitmapTextureFromPath:cachePath withScene:scene];
	[self setThumbTexture:texture];
}

-(void)setClipID:(NSString*)clipID{
	if(m_clipID)
		[m_clipID release];
	[clipID retain];
	m_clipID = clipID;
}

-(NSString*)clipID{
	return m_clipID;
}

-(float)rate{
	return m_rate;
}

-(void)setRate:(float)rate{
	m_rate = rate;
}

-(long)rateCount{
	return m_rateCount;
}

-(void)setRateCount:(long)rateCount{
	m_rateCount = rateCount;
}

-(float)viewerRate{
	return m_viewerRate;
}

-(void)setViewerRate:(float)viewerRate{
	m_viewerRate = viewerRate;
}


-(CTVClipMenuItemLayer*)menuItemLayer{
	return m_menuItemLayer;
}


-(void)setMenuItemLayer:(CTVClipMenuItemLayer*)menuItemLayer{
	if(m_menuItemLayer){
		[m_menuItemLayer release];
	}
	m_menuItemLayer = menuItemLayer;
	[m_menuItemLayer retain];
}


- (id)autorelease{
	id i = [super autorelease];
	return i;
}

- (id)retain{
	id i = [super retain];
	return i;
}

- (oneway void)release{
//	int r = [super retainCount];
//	if(r <= 1){
//		NSLog(@"CTVClip - CLIP WILL BE DELETED!");
//	}
	[super release];
}

-(id)pChannel{
	return m_pChannel;
}

-(void)setChannelPointer:(id)pChannel{
	if(m_pChannel)
		[m_pChannel release];

	m_pChannel = pChannel; //pointer to channel, no reference counting on this

	[m_pChannel retain];
}


-(BOOL)isSane{
	BOOL ret;
	
	if( m_title == nil || m_info == nil || m_url == nil || m_thumbUrl == nil || m_clipID == nil){
		ret = FALSE;
	}else{
		ret = TRUE;
	}
	
	return ret;
}

@end
